package com.wyh.thread;


import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * 创建线程的方式
 */
public class Main {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //继承Thread类并重写run方法
        MyThread myThread = new MyThread();
        myThread.start();

        //创建Thread实例并重写run方法
        Thread thread = new Thread(()-> System.out.println("Thread......"));
        thread.start();

        //实现Callable接口 + futureTask
        FutureTask<String> futureTask = new FutureTask<>(()->"Callable......");
        Thread thread1 = new Thread(futureTask);
        thread1.start();
        System.out.println(futureTask.get());

        //executor线程池
        Executor executor = Executors.newFixedThreadPool(2);
        FutureTask<String> futureTask1 = new FutureTask<>(()->"FutureTask......");
        executor.execute(futureTask1);
        System.out.println(futureTask1.get());

    }
}
